package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Collection; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import java.util.Map; 
 import com.opensymphony.xwork2.ActionContext; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblThongTinNhomLopMonHoc;
import com.lb.jwitter.service.TblThongTinNhomLopMonHocService;
import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

import com.lb.jwitter.service.TblThongTinTKB;
import com.lb.jwitter.service.TblThongTinTKBService;

import com.lb.jwitter.service.TblCanBo;
import com.lb.jwitter.service.TblCanBoService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblThongTinNhomLopMonHocInsertAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private Long id; 
    public void setId(Long id) {
       this.id = id;
 }

    private String ten; 
    public void setTen(String ten) {
       this.ten = ten;
 }

    public String getTen() {
       return ten;
 }

    private String ma; 
    public void setMa(String ma) {
       this.ma = ma;
 }

    public String getMa() {
       return ma;
 }

    private int dotDKId; 
    public void setDotDKId(int dotDKId) {
       this.dotDKId = dotDKId;
 }

    public int getDotDKId() {
       return dotDKId;
 }

    private TblDKMHDotDKService tblDKMHDotDKService; 

    private int monHocId; 
    public void setMonHocId(int monHocId) {
       this.monHocId = monHocId;
 }

    public int getMonHocId() {
       return monHocId;
 }

    private TblCTDTMonHocService tblCTDTMonHocService; 

    private int tKBId; 
    public void setTKBId(int tKBId) {
       this.tKBId = tKBId;
 }

    public int getTKBId() {
       return tKBId;
 }

    private TblThongTinTKBService tblThongTinTKBService; 

    private int canBoId; 
    public void setCanBoId(int canBoId) {
       this.canBoId = canBoId;
 }

    public int getCanBoId() {
       return canBoId;
 }

    private TblCanBoService tblCanBoService; 

    private String ngayCapNhat; 
    public void setNgayCapNhat(String ngayCapNhat) {
       this.ngayCapNhat = ngayCapNhat;
 }

    public String getNgayCapNhat() {
       return ngayCapNhat;
 }

    private TblThongTinNhomLopMonHoc tblThongTinNhomLopMonHoc; 
    public TblThongTinNhomLopMonHoc  getTblThongTinNhomLopMonHoc() {
        return tblThongTinNhomLopMonHoc;
 }

    private TblThongTinNhomLopMonHocService tblThongTinNhomLopMonHocService; 

	private int preInsert(Message msg, TblThongTinNhomLopMonHoc obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postInsert(Message msg, TblThongTinNhomLopMonHoc obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_ThongTin_NhomLop_MonHoc", "them")){ 
        return "noprivilege"; 
    } 
        tblThongTinNhomLopMonHocService = (TblThongTinNhomLopMonHocService) context.getBean("tbl_ThongTin_NhomLop_MonHocClient"); 
        tblDKMHDotDKService = (TblDKMHDotDKService) context.getBean("tbl_DKMH_DotDKClient"); 

        tblCTDTMonHocService = (TblCTDTMonHocService) context.getBean("tbl_CTDT_MonHocClient"); 

        tblThongTinTKBService = (TblThongTinTKBService) context.getBean("tbl_ThongTin_TKBClient"); 

        tblCanBoService = (TblCanBoService) context.getBean("tbl_CanBoClient"); 

        msg = new Message(); 
        tblThongTinNhomLopMonHoc = new TblThongTinNhomLopMonHoc(); 
        tblThongTinNhomLopMonHoc.setTen(ten); 
        tblThongTinNhomLopMonHoc.setMa(ma); 
        tblThongTinNhomLopMonHoc.setDotDKId(tblDKMHDotDKService.gettblDKMHDotDK(new Long(dotDKId))); 
        
        tblThongTinNhomLopMonHoc.setMonHocId(tblCTDTMonHocService.gettblCTDTMonHoc(new Long(monHocId)));
        
        
//        tblThongTinNhomLopMonHoc.setTKBId(tblThongTinTKBService.gettblThongTinTKB(new Long(tKBId))); 
        
        tblThongTinNhomLopMonHoc.setCanBoId(taiKhoanDangNhap.getCanBoId()); 
       DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
       Date dd = new Date(); 
       GregorianCalendar c = new GregorianCalendar(); 
       c.setTime(dd);
       XMLGregorianCalendar d = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
        tblThongTinNhomLopMonHoc.setNgayCapNhat(d); 
        preInsert(msg,tblThongTinNhomLopMonHoc); 
       if (msg.isPreMessage_b()) 
       { 
           id = tblThongTinNhomLopMonHocService.createtblThongTinNhomLopMonHoc(tblThongTinNhomLopMonHoc); 
           postInsert(msg, tblThongTinNhomLopMonHoc); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
       tblThongTinNhomLopMonHoc.setId(id); 
       if(pageSize == 0){ 
           pageSize = 20; 
       } 
        if(page == 0){ 
           page =1; 
       } 
      dataString = ""; 
      dataString += "&id="; 
      dataString += "&ten="; 
      dataString += "&ma="; 
      dataString += "&dotDKId="; 
      dataString += "&monHocId="; 
      dataString += "&tKBId="; 
      dataString += "&canBoId="; 
      dataString += "&ngayCapNhat="; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Insert tbl_ThongTin_NhomLop_MonHoc Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
